<?php
define('ABSPATH', dirname(__FILE__));
require_once ABSPATH . '/../inc/Torrent.class.php';
require_once ABSPATH . '/../inc/Lightbenc.class.php';

if(isset($_GET['file']) && !empty($_GET['file'])){
    $f = ABSPATH . '/../torrent/' . $_GET['file'];
    if(file_exists($f)){
        $torrent = new Torrent($f);
        var_dump($torrent);
        $Lightbenc = new Lightbenc();
        $file_info = $Lightbenc->bdecode_getinfo($f);
        var_dump($file_info);
    }
    exit;
}

$logs = array();
if(false != ($handle = opendir(ABSPATH . '/../torrent/'))){
    $i = 0;
    // 循环获取记录文件
    while(false !== ($file = readdir($handle))){
        if($file != '.' && $file != '..' && strpos($file, '.')){
            if(strtolower(substr($file, strrpos($file, '.') + 1)) == 'torrent')
                $logs[$i] = $file;

            $i++;
        }
    }
    // 关闭目录
    closedir($handle);
}

echo "<ul>";
foreach($logs as $log){
    echo '<li><a href="view-source:http://128.199.164.43/bt.php?file=' . $log . '" target="_blank">' . $log . '</a> - (' . filesize(ABSPATH . '/../torrent/' . $log) . ')</li>';
}
echo "</ul>";